package com.a23qws.stop;

import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ListView;

public class ListViewWithHeadView extends ListView {

	private final String TAG = "ListViewWithHeadView";
	private ScrollListener listener;
	public static boolean flg = false;

	public ListViewWithHeadView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
	}

	public ListViewWithHeadView(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public ListViewWithHeadView(Context context) {
		this(context, null);
	}

	private Handler mHandler = new Handler() {

		public void handleMessage(android.os.Message msg) {

			Log.d(TAG, "mHandler >>>>>>>> ");
			if (listener == null) {
				throw new RuntimeException("listener is null");
			}
			listener.scroll();
			if (flg) {
				mHandler.sendMessageDelayed(mHandler.obtainMessage(), 5);
			}
		};
	};

	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		if (listener == null) {
			throw new RuntimeException("listener is null");
		}
		listener.scroll();
		switch (ev.getAction()) {
		case MotionEvent.ACTION_UP:
			mHandler.sendMessageDelayed(mHandler.obtainMessage(), 5);
			break;
		}
		return super.onTouchEvent(ev);
	}

	public void setScrollListener(ScrollListener listener) {
		this.listener = listener;
	}

	public interface ScrollListener {

		public void scroll();
	}
}
